const ProjectModel = require('../do/models/project');
class ProjectService {
    async getProject(id) {
        if (!id) {
            return await ProjectModel.findAll({ 'order': [['createdAt', 'DESC']] });
        }
        return await ProjectModel.findOne({
            where: {
                id: id
            }
        })
    }
    async getProjectUp() {
        return await ProjectModel.findAll({ 'order': [['createdAt', 'DESC']], where: { status: 1 } });
    }
    async createProject(data) {
        return await ProjectModel.create(data);
    }
    async destroyProject(id) {
        return await ProjectModel.destroy({
            where: { id: id }
        })
    }
    async updateProject(id, data) {
        let { projectimg, projectname, projectlink } = data;
        if (projectimg) {
            return await ProjectModel.update({
                projectimg,
                projectname,
                projectlink
            }, { where: { id: id } })
        } else {
            return await ProjectModel.update({
                projectname,
                projectlink
            }, { where: { id: id } })
        }
    }
    async changeStatusProject(id, status) {
        return await ProjectModel.update({
            status
        }, {
            where: {
                id
            }
        })
    }
}
module.exports = new ProjectService();